package com.feihao.zhou.demo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class ArrayListTest {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();

        Student s1 = new Student("张三", 13);
        Student s2 = new Student("王五", 22);
        Student s3 = new Student("啊流", 18);
        //开发2新增
        Student s4 = new Student("sanyi", 19);

        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);

        System.out.println(students);

        System.out.println("\n");

        //按照年龄升序排序遍历：
        Collections.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });


        for (Student student : students) {
            System.out.println(student);
        }
    }
}
